import { DynamicModule, Module } from '@nestjs/common';
import { AmqpClientService } from './amqp-client.service';
import { ConnectOptions } from './type/ConnectOptions';

@Module({
  providers: [AmqpClientService],
  exports: [AmqpClientService],
})
export class AmqpClientModule {
	static forRootAsync(options: {
		imports?: any[];
		useFactory: (...args: any[]) => Promise<ConnectOptions> | ConnectOptions;
		inject?: any[];
	  }): DynamicModule {
		const providers = [
		  {
			provide: 'AMQP_CONNECT_OPTIONS',
			useFactory: options.useFactory,
			inject: options.inject || [],
		  },
		  AmqpClientService,
		];
	
		return {
		  module: AmqpClientService,
		  providers: providers,
		  exports: [AmqpClientService],
		};
	}
}
